package com.etoak.controller;


import com.etoak.common.core.vo.PageVO;
import com.etoak.common.core.vo.ResultVO;
import com.etoak.dto.OrderDTO;
import com.etoak.entity.Order;
import com.etoak.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author et2403
 * @since 2024-08-16
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    OrderService orderService;

    /**
     * 创建预制订单
     */
    @PostMapping
    public ResultVO<Object> createOrder(@Validated @RequestBody OrderDTO orderDTO){
        orderService.createOrder(orderDTO);
        return ResultVO.success();
    }

    /**
     * 查询预制订单
     */
    @GetMapping
    public ResultVO<PageVO<Order>> getList(@RequestParam(required = false,defaultValue = "1") int pageNum,
                                           @RequestParam(required = false,defaultValue = "5")int pageSize){
        PageVO<Order> data = orderService.getList(pageNum,pageSize);
        return ResultVO.success(data);
    }

}

